package com.xwj.auction.dao;

import com.xwj.auction.domain.AuctionItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author xwj
 * @date 2020/5/8
 */
@Repository
@Mapper
public interface AuctionItemMapper {

    @Select("select * from auction_item where id = #{id} for update")
    AuctionItem selectForUpdate(Long id);

    @Select("select id,name,status,price,last_rob_pay_dead_time as lastRobPayDeadTime from auction_item where id = #{id}")
    AuctionItem select(Long id);

    @Update("update auction_item set status=1 where id = #{id}")
    int updateStatus(Long id);

    @Update("update auction_item set status=1 where id = #{id} and status=0")
    int updateStatusByVersion(Long id);

    @Update("update auction_item set price=#{newPrice} where id = #{id} and price=#{oldPrice} and status=0")
    int updatePrice(@Param("id") Long id, @Param("oldPrice") Integer oldPrice, @Param("newPrice") Integer newPrice);

    int updateLastRobPayDeadTime(@Param("id") Long id, @Param("expectLastRobPayDeadTime") Date expectLastRobPayDeadTime, @Param("updateLastRobPayDeadTime") Date updateLastRobPayDeadTime);
}
